package com.csproj.basic.repository;

import com.csproj.basic.domain.Path;
import com.csproj.basic.repository.custom.PathRepositoryCustom;
import org.springframework.stereotype.Repository;

import org.springframework.data.jpa.repository.*;

import java.util.List;


/**
 * Spring Data JPA repository for the Path entity.
 */
@SuppressWarnings("unused")
@Repository
public interface PathRepository extends JpaRepository<Path, String>, PathRepositoryCustom {
    /**
     * 根据ids查询区域信息
     * @author LM
     * @date   2018-09-18
     * @param ids
     * @return
     */
    @Query(" from Path where id in (?1) ")
    List<Path> findByIds(String[] ids);


    /**
     * 根据ID删除数据
     * @author LM
     * @date   2018-09-18
     * @param id 机构id
     */
    @Modifying
    @Query("UPDATE Path SET deletedFlag = 1 where id = ?1")
    void delete(String id);

    /**
     * 根据ID删除数据
     * @author LM
     * @date   2018-09-18
     * @param id 机构id
     */
    @Query(" from Path where deletedFlag = 0 and id = ?1")
    Path findById(String id);

    Path findFirstByPathNoAndDeletedFlagIsFalse(String pathNo);
    @Query(" from Path where enableFlag = 1 and deletedFlag = 0")
    List<Path> findAllEnabled();

    /**
     * 根据机构ids，批量删除区域信息
     * @param ids
     */
    @Modifying
    @Query(" update Path set deletedFlag = 1 where id in (?1) ")
    void deleteIds(String[] ids);

    /**
     * 将仓库间的所有绑定路径设为非默认路径
     * @param startWarehouseId
     * @param endWarehouseId
     */
    @Modifying
    @Query(" update Path set defaultFlag = false where startWarehouseId = ?1 and endWarehouseId=?2")
    void updateNotDefault(String startWarehouseId, String endWarehouseId);

    /**
     * 修改启用禁用状态
     * @param id
     * @param reason
     * @param enableFlag
     * @return
     */
    @Modifying
    @Query(" update Path  set reason= ?2 , enableFlag = ?3 where id = ?1 ")
    void updateEnableFlag(String id, String reason, Boolean enableFlag);
}
